home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / int.h < prev    next >
C/C++ Source or Header  |  1996-01-30  |  14KB  |  389 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. /*    +---------------------------------------------------+
  11.       |                           |
  12.       |         I N T E R P     M A I N          |
  13.       |                           |
  14.       |           (C Version)              |
  15.       |                           |
  16.       |   Adapted From Low Level SETL version written by  |
  17.       |                           |
  18.       |          Monte Zweben              |
  19.       |           Philippe Kruchten           |
  20.       |           Jean-Pierre Rosen           |
  21.       |                           |
  22.       |    Original High Level SETL version written by      |
  23.       |                           |
  24.       |           Robert B. K. Dewar          |
  25.       |           Clint Goss              |
  26.       |           Tracey M. Siesser           |
  27.       |           Bernard D. Banner           |
  28.       |           Stephen C. Bryant           |
  29.       |          Gerry Fisher              |
  30.       |                           |
  31.       |          C version written by          |
  32.       |                           |
  33.       |           Robert B. K. Dewar          |
  34.       |                           |
  35.       +---------------------------------------------------+             */
  36.  
  37. #include <stdio.h>
  38.  
  39. /*  This module contains constants used in all parts of the interpretor */
  40.  
  41. /*
  42.  *  General use constants
  43.  *  ---------------------
  44.  */
  45.  
  46. #define VERSION            "9-25-85"           /* version identification */
  47. #define NB_REGISTERS       6
  48. #define ADA_MAX_REAL       8.507055E+37           /* maximum real with safety */
  49. #ifndef TRUE
  50. #define TRUE           1               /* boolean true = Ada true */
  51. #endif
  52. #ifndef FALSE
  53. #define FALSE           0               /* boolean false = Ada false */
  54. #endif
  55. #define MIN_LONG       ((long)0x80000000)           /* minimum fixed value */
  56. #define MAX_LONG       ((long)0x7fffffff)           /* maximum fixed value */
  57. #define ENDLESS        -1               /* value for endless delay */
  58. #define NULL_INT       ((int *)0)           /* null pointer value */
  59.  
  60. /* Special task values, note that OWNER_WAITING must be less than NULL_TASK
  61.  * when two task numbers are compared. This is required for correct functioning
  62.  * of the tasking code.
  63.  */
  64.  
  65. #define NULL_TASK       -1               /* null task pointer value */
  66. #define OWNER_WAITING       -2               /* minimum fixed value */
  67.  
  68. /* Mask for stack access = MAX_TASKS - 1.
  69.  * Note that MAX_TASKS must be a power of two.
  70.  */
  71.  
  72. #define TMASK              0177
  73.  
  74. /* Default Values */
  75.  
  76. #define SECURITY_LEVEL 50 /* free words in the stack before calls */
  77. #define TASK_CODE_OFFSET 4 /* starting offset in code segment for task */
  78.  
  79. /* Size of long and float values in words (ints) */
  80.  
  81. #define WORDS_FLOAT (sizeof(float)/sizeof(int))
  82. #define WORDS_LONG   (sizeof(long)/sizeof(int))
  83. #define WORDS_PTR  (sizeof(int *)/sizeof(int))
  84. /* WORDS_HDR is number of words in header of heap block */
  85. #define WORDS_HDR  (1 + WORDS_PTR)
  86.  
  87. /* Definition of a stack frame */
  88.  
  89. #define SF_PREVIOUS_SFP          0
  90. #define SF_RETURN_CS             1
  91. #define SF_RETURN_IP             2
  92.  
  93. /* Definition of exceptions */
  94.  
  95. #define CONSTRAINT_ERROR         1
  96. #define NUMERIC_ERROR             1
  97. #define PROGRAM_ERROR             3
  98. #define STORAGE_ERROR             4
  99. #define TASKING_ERROR             5
  100. #define SYSTEM_ERROR             6
  101. /* these come from predef and not be defined here */
  102. #define STATUS_ERROR             7
  103. #define MODE_ERROR             8
  104. #define NAME_ERROR             9
  105. #define USE_ERROR             10
  106. #define DEVICE_ERROR             11
  107. #define END_ERROR             12
  108. #define DATA_ERROR             13
  109. #define LAYOUT_ERROR             14
  110. #define TIME_ERROR             15
  111.  
  112. /* Attributes */
  113.  
  114. /* Those attributes marked "static" are treated by the front end and do not
  115.  * appear as arguments to the attribute instruction. Note that POS and VAL
  116.  * are not static, but do not appear as attribute instruction arguments
  117. Static:
  118. A_AFT ATTR_BASE ATTR_DELTA ATTR_DIGITS ATTR_EMAX ATTR_EPSILON ATTR_FIRST_BIT
  119. ATTR_MACHINE_EMAX ATTR_MACHINE_EMIN ATTR_MACHINE_MANTISSA
  120. ATTR_MACHINE_OVERFLOWS ATTR_MACHINE_RADIX ATTR_MACHINE_ROUNDS
  121. ATTR_POS       -- not static but generates nothing
  122. ATTR_SAFE_EMAX ATTR_SAFE_LARGE ATTR_SAFE_SMALL
  123. ATTR_SMALL ATTR_STORAGE_SIZE(?)
  124. ATTR_VAL --not static but generate a qual_range
  125.  */
  126. #include "attr.h"
  127. #include "ops.h"
  128.  
  129.  
  130. /* General Addressing Macros */
  131.  
  132. /*
  133.  *  LONG(ptr)        Pointer regarded as pointer to long value
  134.  *  ADDR(ds,off)    Get address from data seg offset values
  135.  *  ADDRL(ds,off)    Get address of long from data seg offset values
  136.  *  POP(val)        Pop int val off stack
  137.  *  POPF(fval)        Pop float fval off stack
  138.  *  POPL(lval)        Pop long lvall off stack
  139.  *  POPP(lval)        Pop pointer from stack
  140.  *  POP_ADDR(bs,of)    Pop base/offset address from stack
  141.  *  POP_PTR(ptr)    Pop pointer from stack
  142.  *  PUSH(val)        Push int val onto stack
  143.  *  PUSHF(fval)        Push float fval onto stack
  144.  *  PUSHL(lval)        Push long lval onto stack (also used for fixed)
  145.  *  PUSHP(lval)        Push pointer onto stack
  146.  *  PUSH_ADDR(bs,of)    Push address onto stack
  147.  *  TOS            Reference top of stack as int
  148.  *  TOSF        Reference top of stack as float
  149.  *  TOSL        Reference top of stack as long
  150.  *  TOSM(n)        Reference n'th item from top (TOS = TOSM(0))
  151.  *  BLOCK_FRAME        Pointer to the current block frame
  152.  *  STACK_FRAME(dsp)    Access an element from the current stack frame
  153.  */
  154.  
  155.  
  156. #define LONG(ptr)      ((long *)(ptr))
  157. #define ADDR(ds,off)      (data_segments[ds] + off)
  158. #define ADDRL(ds,off)      (LONG(data_segments[ds] + off))
  159. #define POP(val)      val=cur_stack[cur_stackptr--]
  160. #define POPF(fval)      fval = TOSF,cur_stackptr -= WORDS_FLOAT
  161. #define POPL(lval)      lval = TOSL,cur_stackptr -= WORDS_LONG
  162. #define POPP(lval)      POPL((long)lval)
  163. #define POP_ADDR(bs,of)   POP(of),POP(bs)
  164. #define POP_PTR(pt)       pt=ADDR(TOSM(1),TOS),cur_stackptr -= 2
  165. #define PUSH(val)      cur_stack[++cur_stackptr] = val
  166. #define PUSHF(fval)      cur_stackptr+=WORDS_FLOAT,TOSF=fval
  167. #define PUSHL(lval)      cur_stackptr+=WORDS_FLOAT,TOSL=lval
  168. #define PUSHP(lval)      PUSHL((long)lval)
  169. #define PUSH_ADDR(bs,of)  PUSH(bs),PUSH(of)
  170. #define TOS          (cur_stack[cur_stackptr])
  171. #define TOSF          *((float *)(cur_stack+cur_stackptr+1-WORDS_FLOAT))
  172. #define TOSL          *(LONG(cur_stack+cur_stackptr+1-WORDS_LONG))
  173. #define TOSML(n)      *(LONG(cur_stack+cur_stackptr+1-((n)+1)*WORDS_LONG))
  174. #define TOSM(n)       (cur_stack[cur_stackptr-(n)])
  175. #define BLOCK_FRAME      ((struct bf *)(cur_stack+bfp))
  176. #define ARB_BLOCK_FRAME(t,b) ((struct bf *)((STACK(t))+(b)))
  177. #define STACK_FRAME(dsp)  cur_stack[sfp+dsp]
  178.  
  179. /* Macros for accessing fields of block frame */
  180.  
  181. #define BF_PREVIOUS_BFP(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_previous_bfp
  182. #define BF_DATA_LINK(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_data_link
  183. #define BF_TASKS_DECLARED(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_tasks_declared
  184. #define BF_SUBTASKS(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_subtasks
  185. #define BF_HANDLER(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_handler
  186. #define BF_NUM_NOTERM(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_num_noterm
  187. #define BF_NUM_DEPS(t,b)     (ARB_BLOCK_FRAME(t,b))->bf_num_deps
  188.  
  189. #define MY_PREVIOUS_BFP          (BLOCK_FRAME)->bf_previous_bfp
  190. #define MY_DATA_LINK          (BLOCK_FRAME)->bf_data_link
  191. #define MY_TASKS_DECLARED    (BLOCK_FRAME)->bf_tasks_declared
  192. #define MY_SUBTASKS              (BLOCK_FRAME)->bf_subtasks
  193. #define MY_HANDLER              (BLOCK_FRAME)->bf_handler
  194. #define MY_BF_NUM_NOTERM    (BLOCK_FRAME)->bf_num_noterm
  195. #define MY_BF_NUM_DEPS        (BLOCK_FRAME)->bf_num_deps
  196.  
  197. /* Utility Macros */
  198.  
  199. #define ABS(v)          ((v) >= 0 ? (v) : -(v))
  200. #define BOOL(v)       ((v) % 2)
  201. #define MAX(a,b)      (((a) >= (b)) ? (a) : (b))
  202. #define MIN(a,b)      (((a) <= (b)) ? (a) : (b))
  203. #define SIGN(a)       (((a) > 0) - ((a) < 0))
  204.  
  205.  
  206. /* Block Frame */
  207.  
  208.    struct bf {
  209.       int      bf_previous_bfp;    /* offset to previous block frame */
  210.       int     *bf_data_link;     /* head of chain of data blocks */
  211.       int     *bf_tasks_declared;    /* head of chain of created tasks */
  212.       int      bf_num_noterm;    /* number of non terminated */
  213.       int      bf_num_deps;        /* number of non terminated */
  214.       int      bf_subtasks;        /* head of chain of dependent tasks */
  215.       int      bf_handler;        /* IP of exception handler */
  216.    };
  217.  
  218. /** NEW TYPES **/
  219.  
  220. /* Item Type for Multi-Queues */
  221.  
  222.    struct rts_item {
  223.       int      mult, save_mult;    /* multiplicity count             */
  224.       int      parent;            /* parent tcb index               */
  225.       int      *tcbs;            /* array of tcb nums of new tasks */
  226.       int      type;                /* action - create or activate    */
  227.       int      prio;                 /* priority of rts item           */
  228.       int      templ_base;        /* task's template's base         */
  229.       int      templ_off;        /* task's template's offset       */
  230.       int      master_task;        /* master task number             */
  231.       int       master_block;        /* offset in master task's stack  */
  232.       struct rts_item *next;    /* pointer to next item           */
  233.    };
  234.  
  235. /* Lock type */
  236.  
  237. #define LOCK(a)        (a)->lock
  238.    struct lock_type {
  239.       int      add_lock;         /* lock needed by callers of entry */
  240.       int      del_lock;         /* lock needed by owner of entry   */
  241.    };
  242.  
  243. /* Ready queue header type */
  244.  
  245.    struct ready_q {
  246.       struct lock_type lock;           /* lock needed by callers of entry */
  247.       int      count;                 /* number of tasks queued on entry */
  248.       struct rts_item *first;        /* first task queued on entry      */
  249.       struct rts_item *last;        /* last task queued on entry       */
  250.       int      first_mult;            /* multiplicity left of first item */
  251.    };
  252.  
  253. /* Entry Queue item type */
  254.  
  255.    struct q_item {
  256.       int      flag;            /* bit on if has not been removed */
  257.       int      task;             /* task id               */
  258.       struct q_item *next;        /* next on chain          */
  259.    };
  260.  
  261. /* Entry type in Task Control Block */
  262.  
  263.    struct entry_type {
  264.       struct lock_type lock;           /* lock needed by callers of entry */
  265.       int      count;         /* number of tasks queued on entry */
  266.       struct q_item *first;        /* first task queued on entry      */
  267.       struct q_item *last;        /* last task queued on entry       */
  268.       int      guard;          /* guard of the entry              */
  269.    };
  270.  
  271. /* Io_item type in Task Control Block */
  272.  
  273.    struct io_item_type {
  274.       int     task;
  275.       int       flag;
  276.       long      delta;
  277.       struct io_item_type *next;
  278.    };
  279.  
  280. /* Task Control Block */
  281. /*  Note:  The first two fields (tbase and toff) must appear in that order */
  282. /*          as the first two fields of the tcb ...                */
  283.  
  284.    struct tcb_type {
  285.       int      tcb_tbase;            /* task base address               */
  286.       int      tcb_toff;             /* task offset                     */
  287.       int      tcb_abnormal;            /* flag set when task is aborted   */
  288.       int      tcb_action;            /* action executing when blocked   */
  289.       int      tcb_brother;            /* next direct dep. of master const*/
  290.       int         *tcb_block_ptr;    /* currently executing block frame */
  291.       struct q_item *tcb_entry_item; /* pointer to item in entry queue  */
  292.       struct entry_type *tcb_curr_entry;/* pointer to current entry queue  */
  293.       int      tcb_event;            /* event to unblock (set by others)*/
  294.       int      tcb_exception;        /* current exception raised        */
  295.       int      tcb_first;            /* first field                     */
  296.       int      tcb_id;                /* index of task in RTS item       */
  297.       struct io_item_type *tcb_io_item;    /* curr. io_item (made when delay) */
  298.       int      tcb_master_task;         /* number of the master task       */
  299.       int         tcb_master_block; /* number of the master block      */
  300.       int      tcb_next;                /* ptr to next task to activate OR */
  301.                     /* prev. partner of my partner     */ 
  302.       int      tcb_num_items;        /* number of items                 */
  303.       int      tcb_num_noterm;        /* # of nonterminatable direct dep.*/
  304.       int      tcb_num_deps;            /* # of nonterminatd direct dep.   */
  305.       int      tcb_num_entries;        /* # of entries                    */
  306.       int      tcb_num_events;        /* # of pending events             */
  307.       int      tcb_parent;            /* tcb index of parent task        */
  308.       int      tcb_prio;                /* task priority                   */
  309.       int      tcb_rdv;                /* flag set when executes open acpt*/
  310.       struct rts_item *tcb_rts_item;/* my current rts item             */
  311.       int      tcb_save_prio;        /* task save priority              */
  312.       int      tcb_serviced;            /* current calling partners chain  */
  313.       int      tcb_status;            /* current status, set by me       */
  314.       int      tcb_what;                /* entry called (set by caller)    */
  315.       int      tcb_who;                /* who called entry (set by caller)*/
  316.       struct entry_type  tcb_entry;    /* list of entries            */
  317.    };
  318.  
  319.  
  320.  
  321.  
  322. /* Functions returning other than INT values */
  323.  
  324. #include "type.h"
  325.  
  326. #define FIX_BAS 128
  327. #define FIX_DIGS 7
  328. #define FIX_LENGTH 19
  329.  
  330. /* rename some procedures to avoid name conflicts with library routines
  331.  * on pc or bsd (these confuse lint output).
  332.  */
  333. #define abort abortp
  334. #define kill killp
  335. #define signal signalp
  336. #define wait waitp
  337.  
  338. /*
  339.  *                         P R E D E F
  340.  */
  341. /* GENERAL DATA STRUCTURES FOR FILES
  342.  *
  343.  * Files in Ada are described by a structure called an AFCB (Ada File
  344.  * Control Block). The vector afcb contains pointers to allocated AFCB's
  345.  * with a null entry indicating an unused index value. An Ada file value
  346.  * is an index into this vector, with zero indicating a closed file.
  347. */
  348.  
  349. struct afcb {
  350.  
  351.    /* Fields used for all file modes */
  352.  
  353.    FILE    *io_fdesc;         /* file descriptor (null if not associated) */
  354.    char *io_fname;         /* file name */
  355.    char *io_form;         /* file form string */
  356.    int    io_mode;         /* file mode */
  357.  
  358.    /* Fields used only for DIRECT_IO, undefined for other cases */
  359.  
  360.    int dio_pos;          /* current file index */
  361.    int dio_length;         /* length of record */
  362.    int dio_size;         /* number of records currently written */
  363.  
  364.    /* Fields used only for TEXT_IO, undefined for other cases */
  365.  
  366.    int    tio_page;         /* page number */
  367.    int    tio_line;         /* line number */
  368.    int    tio_col;         /* column number */
  369.    int    tio_line_length;     /* line length, 0 = unbounded */
  370.    int    tio_page_length;     /* page length, 0 = unbounded */
  371.  
  372.    /* The following fields implement up to a three character look ahead
  373.     * for TEXT_IO input files, with tio_count being the number of characters
  374.     * currently stored. If tio_count is less than 3, it means that the end
  375.     * of file is after the last stored character.
  376.    */
  377.  
  378.    int     tio_count;         /* count of chars stored in tio_look_ahead */
  379.    char  tio_look_ahead[3];  /* three characters of look ahead */
  380.  
  381. };
  382.  
  383. /* Structure used to remember names of temporary files in linked list */
  384.  
  385. struct tfile {
  386.    struct tfile *tfile_next;    /* next entry on list */
  387.    char tfile_name [15];
  388. };
  389.